<template>
    <div>
      <el-card style="width: 50%">
        <el-form ref="formRef" :model="user" :rules="rules" label-width="100px" style="padding-right: 50px">
          <el-form-item label="原始密码" prop="password">
            <el-input show-password v-model="user.password" placeholder="原始密码"></el-input>
          </el-form-item>
          <el-form-item label="新密码" prop="newPassword">
            <el-input show-password v-model="user.newPassword" placeholder="新密码"></el-input>
          </el-form-item>
          <el-form-item label="确认新密码" prop="confirmPassword">
            <el-input show-password v-model="user.confirmPassword" placeholder="确认密码"></el-input>
          </el-form-item>
          <div style="text-align: center; margin-bottom: 20px">
            <el-button type="primary" @click="update">确认修改</el-button>
          </div>
        </el-form>
      </el-card>
    </div>
  </template>
    <script>
    import service from '@/request';
    export default {
      name: "AdminPerson",
      data() {
        return {
          user:{}
        }
      },
      created() {
    
      },
      mounted(){
          this.user=JSON.parse(window.localStorage.getItem("userinfo"))
      },
      methods: {
          handleAvatarSuccess(response, file, fileList) {
              this.$set(this.user, 'avatar', response.data)
        },
       async update() {
        if(this.user.passnewPassword !==this.user.confirmPassword ){
            this.$message.warning("新密码和确认密码不一样")
         
        }else{
            if(this.user.role == 'BUSINESS'){
            const res=await service.post("/Business/updatePassword",{
                id:this.user.id,
                username:this.user.username,
                password:this.user.newPassword
            });
         console.log(res);
         if(res.code == 200){
          this.$message.success(res.data)
         
         }
        }
        }
        
       
        },
        handleAvatarSuccess1(response, file, fileList) {
          // 把user的头像属性换成上传的图片的链接
          this.$set(this.user, 'license', response.data)
        },
      }
    }
    </script>